<template>
    <div class="user_wrapper">
        <div class="content_wrapper">
            <a-dropdown @visibleChange="userVisibleChange">
                <span class="action">
                    <a-image class="avatar" size="small" :src="userInfo.avatar" :preview="false" />

                    <span class="nickname">
                        {{ userInfo.userName }}
                        <caret-down-outlined :class="`caretup_${state.userVisible}`" />
                    </span>
                </span>
                <template #overlay>
                    <a-menu class="user-dropdown-menu-wrapper">
                        <a-menu-item key="0">
                            <router-link to="/account/center"> <user-outlined />个人中心 </router-link>
                        </a-menu-item>
                        <a-menu-item key="1">
                            <a href="javascript:;" @click="changePassword"> <key-outlined />修改密码 </a>
                        </a-menu-item>
                        <!-- <a-menu-item key="2" disabled>
                            <setting-outlined />测试
                        </a-menu-item>-->
                        <a-menu-divider />
                        <a-menu-item key="3">
                            <a href="javascript:;" @click="handleLogout"> <poweroff-outlined />退出登录 </a>
                        </a-menu-item>
                    </a-menu>
                </template>
            </a-dropdown>
        </div>
        <div class="vertical">
            <a-divider style="background-color: #fff" type="vertical" />
        </div>
    </div>
</template>

<script lang="ts" setup>
import { ExclamationCircleOutlined } from '@ant-design/icons-vue'
import { message, Modal } from 'ant-design-vue'
import { reactive, createVNode } from 'vue'

const state = reactive({
    userVisible: false,
    changePasswordVisible: false,
    changePasswordForm: {
        oldPassword: '',
        newPassword: '',
        confirmPassword: ''
    },
    submitLoading: false
})
const changePassword = () => {
    state.changePasswordVisible = true
}

const userVisibleChange = () => {}

const userInfo = {
    avatar: '',
    userName: 'xxx'
}

const handleLogout = () => {
    Modal.confirm({
        title: '提示',
        icon: createVNode(ExclamationCircleOutlined),
        content: '真的要注销登录吗 ?',
        okText: '确定',
        cancelText: '取消',
        onOk() {},
        class: 'test'
    })
}
</script>

<style scoped lang="less">
.user_wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
}
.vertical {
    margin: 0px 12px;
}
.content_wrapper {
    height: 100%;
    .action {
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        // padding: 0 16px;
        transition: all 0.3s;
        height: 100%;
    }
    :deep(.avatar) {
        width: 24px;
        height: 24px;
        margin-right: 8px;
        border-radius: 50%;
    }
    .nickname {
        color: @body-background;
        font-family: PingFangSC-Medium, PingFang SC;
        font-size: 14px;
    }

    .caretup_false {
        transition: all 0.25s;
        transform: rotate(0);
    }
    .caretup_true {
        transition: all 0.25s;
        transform: rotate(180deg);
    }
}
</style>
